package cn.hcbycloud.auth.service.impl;

import cn.hcbycloud.common.async.annotation.AsyncTask;
import cn.hcbycloud.common.async.service.IAsyncService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

/**
 * @author gaoh
 * @desc 异步任务测试实现类
 * @date 2022年02月07日 下午 9:17
 */
@Slf4j
@Service("asyncServiceTwo")
@Transactional(rollbackFor = Exception.class)
public class AsyncServiceTwoImpl implements IAsyncService {

    @AsyncTask
    @Async("getAsyncExecutor")
    @Override
    public void execAsyncTask(String taskId) {
        log.info("start taskId: [{}]", taskId);
        StopWatch watch = StopWatch.createStarted();
        log.info("async task running taskId: [{}]", taskId);
        watch.stop();
        log.info("check and import goods success: [{}ms]",
                watch.getTime(TimeUnit.MILLISECONDS));
    }
}